import { getToken } from "@/utils/auth"

const initialState = {
  token: getToken(),
  name: ''
}

const user = (state = initialState, action) => {
  if ( action.type === 'user/setToken' ) {
    return {
      ...state,
      token: action.payload
    }
  }
  if ( action.type === 'user/setName' ) {
    return {
      ...state,
      name: action.payload
    }
  }
  return state
}

export default user